package cn.cdcoder.solr.select;

import cn.cdcoder.solr.BaseSort;

/**
 * 直接选择排序
 * @author xusirun
 * @Date 2017/3/21 13:19
 **/
public class DirectSelectSort extends BaseSort {
    public static void main(String[] args)
    {
        int[] a = getData(20);
        //
        sort(a);
        System.out.println();
        System.out.println("排序之后：");
        for (int i = 0; i < a.length; i++)
        {
            System.out.print(a[i] + " ");
        }

    }


    private static void   sort(int[] array){
        for (int i = 0; i < array.length; i++)
        {
            int min = array[i];
            int n = i; // 最小数的索引
            for (int j = i + 1; j < array.length; j++)
            {
                if (array[j] < min)
                { // 找出最小的数
                    min = array[j];
                    n = j;
                }
            }
            array[n] = array[i];
            array[i] = min;

        }
    }
}
